﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using EyesOfTheDragon.Events;
namespace XRpgLibrary.Events
{
    public interface IPhysics
    {
        Vector2 Position { get; set; }
        Vector2 Velocity { get; set; }
    }
    public class PhysicsSimulation : IUpdate, IPauseable
    {
        public bool Enabled
        {
            get { return _enabled; }
            set { _enabled = value; }
        }
        private bool _enabled = true;
        public static PhysicsSimulation Instance
        {
            get 
            {
                if (_instance == null)
                    _instance = new PhysicsSimulation();
                return _instance; 
            }
        }
        public void Update(GameTime gt)
        {
            float seconds = gt.ElapsedGameTime.Milliseconds/1000f;
            foreach (IPhysics obj in physicsObjects)
            {
                obj.Position += obj.Velocity * seconds;
            }
        }
        public void add(IPhysics obj)
        {
            physicsObjects.Add(obj);
        }
        public void remove(IPhysics obj)
        {
            physicsObjects.Remove(obj);
        }
        private List<IPhysics> physicsObjects = new List<IPhysics>();
        private static PhysicsSimulation _instance;
    }
}
